<?php

/**
 * Apartman form.
 *
 * @package    estate
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class ApartmanForm extends BaseApartmanForm
{
  public function configure()
  {
    $galleryForm = new jwGalleryForm( $this->getObject()->getjwGallery() );  
    $this->embedForm( 'gallery', $galleryForm );
    
    $pricesForm = new ApartmanPricesForm( $this->getObject()->getjwCustomTable() );  
    $this->embedForm( 'prices', $pricesForm );    
  }
  
  public function bind( array $taintedValues = null, array $taintedFiles = null )
  {      
    if ( $this->embeddedForms["gallery"]->getObject()->isNew() )
    {
      unset( $taintedValues["gallery_id"] );      
      $this->getObject()->setjwGallery( $this->embeddedForms["gallery"]->getObject() );
    }
    else
    {
      $taintedValues["gallery_id"] = $this->embeddedForms["gallery"]->getObject()->getId();
    }

    if ( $this->embeddedForms["prices"]->getObject()->isNew() )
    {
      unset( $taintedValues["prices_table_id"] );      
      $this->getObject()->setjwCustomTable( $this->embeddedForms["prices"]->getObject() );
    }
    else
    {
      $taintedValues["prices_table_id"] = $this->embeddedForms["prices"]->getObject()->getId();
    }
    
    jwGalleryForm::updateFromRequest( $this->embeddedForms['gallery'], &$taintedValues['gallery'] );
    $this->embedForm( 'gallery', $this->embeddedForms['gallery'] );
    
    jwCustomTableForm::updateFromRequest( $this->embeddedForms['prices'], &$taintedValues['prices'] );
    $this->embedForm( 'prices', $this->embeddedForms['prices'] );    
      
    parent::bind( $taintedValues, $taintedFiles );
  }
}
